﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Bussiness.Interfaces;
using Truextend.CoffeShop.Model;
using Truextend.Common.Data;

namespace Truextend.CoffeShop.Bussiness
{
    public class RestaurantManager: Repository<Restaurant>, IRestaurantManager
    {

        public RestaurantManager(IUnitOfWork unitOfWork) : base(unitOfWork) { 
        
        }        

        public IList<Restaurant> GetAllExternalRestaurants()
        {
            var context = (CoffeShopEntities)Context;

            var info = from p in context.Restaurant where p.Name != "Truextend" select p;

            return info.ToList();    
        }

        public Restaurant GetRestaurantByOrderId(int orderId)
        {
            var context = (CoffeShopEntities)Context;

            var info = from p in context.Detail join
                       h in context.Product on p.Product.ProductId equals h.ProductId
                       join j in context.Restaurant on h.Restaurant.RestaurantId equals j.RestaurantId
                       where p.Order.OrderId == orderId
                       select j;

            return info.First();

        }
    }
}
